home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / dskut / iau19e.zip / DISKINFO.C < prev    next >
C/C++ Source or Header  |  1991-02-03  |  6KB  |  229 lines

  1. #define MYREV 'A'
  2. /*
  3.  * DISKINFO -- a Turbo 'C' program which will display the current drive
  4.  * parameters for your hard disk(s).  Compiled using version 1.5 of Turbo
  5.  * 'C'.  This program is released into the public domain 8/29/88.  This is
  6.  * NOT a shareware program. It might or might not be supported by the author. 
  7.  *
  8.  * Original code:    8/29/88 D. Bushong This revision:  A  (original) 
  9.  *
  10.  
  11. Revision history 
  12. ========================== 
  13. REV    DATE    BY    Reason for mod / effect obtained 
  14. ======= ======= ======= ================================================== 
  15.     A    2/ 3/91 Bushong    Change of address (no functional changes)
  16.     B     /  / 
  17.     C     /  / 
  18.  
  19.  
  20. */
  21.  
  22. #include <bios.h>
  23. #include <mem.h>
  24. #include <conio.h>
  25. #include <dos.h>
  26. #include <process.h>
  27.  
  28. typedef unsigned char BYTE;
  29. typedef unsigned WORD;
  30.  
  31. struct table {
  32.     WORD maxcyl;
  33.     BYTE maxhead;
  34.     WORD not_used;
  35.     WORD start_precomp;
  36.     BYTE max_burst;
  37.     BYTE control_byte;
  38.     BYTE more_not_used[3];
  39.     WORD landing_zone;
  40.     BYTE sectors_track;
  41.     BYTE rfu;
  42. };
  43. #if ((sizeof(struct table))!=16)
  44. ***Alignment error ! ***
  45. #endif
  46.  
  47. #if (MYREV=='A')
  48. #define MODBY ""
  49. #else
  50. #define MODBY "Modified 00/00/00 by [yourname]"
  51. #endif
  52.  
  53. struct diskinfo {
  54.     unsigned which_drive;
  55.     unsigned number_of_drives;
  56.     unsigned max_heads;
  57.     unsigned max_cylinders;
  58.     unsigned max_sectors;
  59. } info;
  60.  
  61. void hello(void)
  62. {
  63.     clrscr();
  64.     gotoxy(1, 2);
  65.     cprintf("   DISKINFO.... display hard disk information from BIOS and drive table\r\n");
  66.     cprintf("   (%c)   Public domain software from Dave Bushong, Dracut, MA 01826\r\n", MYREV);
  67.     gotoxy(1, 25);
  68.     cprintf("%79s\r\n", MODBY);
  69. }
  70.  
  71. void get_disk_info(struct diskinfo * disk_data)
  72. {
  73.     unsigned buffer[10];
  74.     disk_data->which_drive |= 0x80;
  75.     if (disk_data->which_drive != 0x80 && disk_data->which_drive != 0x81) {
  76.     memset(disk_data, 0, sizeof(struct diskinfo));
  77.     return;
  78.     }
  79.     biosdisk(8, disk_data->which_drive, 0, 1, 1, 1, buffer);
  80.  
  81.     disk_data->number_of_drives = buffer[1] & 0x03;
  82.     disk_data->max_heads = ((buffer[1] & 0x0f00) >> 8);
  83.     disk_data->max_cylinders = (((buffer[0] & 0xc0) << 2) + (buffer[0] >> 8));
  84.     disk_data->max_sectors = buffer[0] & 0x3f;
  85.     return;
  86. }
  87.  
  88. struct table far *tp;
  89.  
  90. void main(void)
  91. {
  92.     /*
  93.      * this program will show what the BIOS thinks is going on with the
  94.      * disks. 
  95.      */
  96.  
  97.     int i;
  98.     static char fs[] = {'%', '7', 'u', '\0'};
  99.     lowvideo();
  100.     _AH = 8;
  101.     _DL = 0x80;
  102.     geninterrupt(0x13);
  103.     i = _DL;            /* hard drive count */
  104.     i &= 3;
  105.  
  106.     hello();
  107.  
  108.     gotoxy(1, 5);
  109.  
  110.     if (i == 0) {
  111.     cprintf("The BIOS reports that there are NO hard drives present.\r\n");
  112.     gotoxy(1, 24);
  113.     return;
  114.     }
  115.     gotoxy(15, 5);
  116.     cprintf("BIOS \"GETPARM\" values");
  117.     gotoxy(56, 5);
  118.     cprintf("Drive Table values");
  119.     gotoxy(19, 7);
  120.     cprintf("Drive 0   Drive 1");
  121.     gotoxy(57, 7);
  122.     cprintf("Drive 0   Drive 1");
  123.     gotoxy(3, 9);
  124.     cprintf("Max. Cylinder");
  125.     gotoxy(7, 10);
  126.     cprintf("Max. Head");
  127.     gotoxy(5, 11);
  128.     cprintf("Max. Sector");
  129.  
  130.     gotoxy(41, 9);
  131.     cprintf("Cylinder count");
  132.     gotoxy(45, 10);
  133.     cprintf("Head count");
  134.     gotoxy(42, 11);
  135.     cprintf("Sectors/track");
  136.     gotoxy(42, 12);
  137.     cprintf("Start precomp");
  138.     gotoxy(42, 13);
  139.     cprintf("Maximum burst");
  140.     gotoxy(43, 14);
  141.     cprintf("Control byte");
  142.     gotoxy(43, 15);
  143.     cprintf("Landing zone");
  144.  
  145.     gotoxy(5, 18);
  146.     cprintf("Note that some values returned from the BIOS are \"zero-based\"; which");
  147.     gotoxy(5, 19);
  148.     cprintf("means that you would start counting at zero.  The drive table is, instead,");
  149.     gotoxy(5, 20);
  150.     cprintf("a one-based count.  For example, if you have four drive heads, they");
  151.     gotoxy(5, 21);
  152.     cprintf("are numbered zero-one-two-three.  The maximum head value would be three.");
  153.     gotoxy(5, 22);
  154.     cprintf("Heads and cylinders start counting at zero; sector numbers start at one.");
  155.     gotoxy(4, 14);
  156.     cprintf("All values shown are in decimal.");
  157.  
  158.     info.which_drive = 0;
  159.     get_disk_info(&info);
  160.     tp = (struct table far *) getvect(0x41);
  161.  
  162.     highvideo();
  163.     gotoxy(19, 9);
  164.     cprintf(fs, info.max_cylinders);
  165.     gotoxy(19, 10);
  166.     cprintf(fs, info.max_heads);
  167.     gotoxy(19, 11);
  168.     cprintf(fs, info.max_sectors);
  169.  
  170.     gotoxy(57, 9);
  171.     cprintf(fs, tp->maxcyl);
  172.     gotoxy(57, 10);
  173.     cprintf(fs, tp->maxhead);
  174.     gotoxy(57, 11);
  175.     cprintf(fs, tp->sectors_track);
  176.     gotoxy(57, 12);
  177.     cprintf(fs, tp->start_precomp);
  178.     gotoxy(57, 13);
  179.     cprintf(fs, tp->max_burst);
  180.     gotoxy(57, 14);
  181.     cprintf(fs, tp->control_byte);
  182.     gotoxy(57, 15);
  183.     cprintf(fs, tp->landing_zone);
  184.     lowvideo();
  185.  
  186.     if (i == 1) {
  187.     for (i = 9; i < 12; i++) {
  188.         gotoxy(33, i);
  189.         cprintf("N/A");
  190.     }
  191.     for (i = 9; i < 16; i++) {
  192.         gotoxy(71, i);
  193.         cprintf("N/A");
  194.     }
  195.     gotoxy(1, 24);
  196.     return;
  197.     }
  198.     highvideo();
  199.  
  200.     info.which_drive = 1;
  201.     get_disk_info(&info);
  202.     tp = (struct table far *) getvect(0x46);
  203.  
  204.     gotoxy(29, 9);
  205.     cprintf(fs, info.max_cylinders);
  206.     gotoxy(29, 10);
  207.     cprintf(fs, info.max_heads);
  208.     gotoxy(29, 11);
  209.     cprintf(fs, info.max_sectors);
  210.  
  211.     gotoxy(67, 9);
  212.     cprintf(fs, tp->maxcyl);
  213.     gotoxy(67, 10);
  214.     cprintf(fs, tp->maxhead);
  215.     gotoxy(67, 11);
  216.     cprintf(fs, tp->sectors_track);
  217.     gotoxy(67, 12);
  218.     cprintf(fs, tp->start_precomp);
  219.     gotoxy(67, 13);
  220.     cprintf(fs, tp->max_burst);
  221.     gotoxy(67, 14);
  222.     cprintf(fs, tp->control_byte);
  223.     gotoxy(67, 15);
  224.     cprintf(fs, tp->landing_zone);
  225.     gotoxy(1, 24);
  226.     lowvideo();
  227.     return;
  228. }
  229.